package com.example;

import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;

/**
 * @Author 郅占伟
 * @ClassName HtmlCodeGenerate
 * @Description TODO
 * @Date 2025年02月21日
 * @Version: 1.0
 */
public class HtmlCodeGenerate {

    @Test
    public void testDockerLog3() {
        // File file = new File("D:\\develop\\gitCode\\java_base\\javaBaisc_introduction\\javaBasic_IO\\log\\buttonName.log");
        File file = new File("D:\\develop\\gitCode\\java_base\\javaBaisc_introduction\\javaBasic_IO\\log\\buttonName.log");

        try (FileReader fileReader = new FileReader(file);
             BufferedReader bufferedReader = new BufferedReader(fileReader);
        ) {
            // 判断文件是否还能读取
            int lineNum = 126;
            String name = "";
            int dbArea = 7;
            int num = 4;
            String lastLine = "";
            String line = "";
            while (bufferedReader.ready()) {
                //lastLine = line;
                String one = bufferedReader.readLine();
//                String two = bufferedReader.readLine();
                String[] splitOne = one.split("\t");
//                String[] splitTwo = two.split(":=");

                if (!"Int".equals(splitOne[1]) && !"Bool".equals(splitOne[1]) && !"Time".equals(splitOne[1]) && !"DInt".equals(splitOne[1])) {
                    name = "轴变量".equals(splitOne[1]) ? splitOne[0] : "默认信号";
                    continue;
                }

//                System.out.println("Siemens_Log_" + lineNum + "(" + num +",\""  + splitOne[0].trim() + "\",\""   + splitTwo[1].substring(splitTwo[1].indexOf("'") + 1, splitTwo[1].lastIndexOf("'")) + "\"" + "," + 54 + "),");

//                //  ALL_INIT("0", "一键初始化", "boolean", (byte) 16, 54);
                int param0 = lineNum;
                String param1 = splitOne[2];
                String param2 = name + splitOne[0];
                String param3 = "Bool".equals(splitOne[1]) ? "boolean" : "int";
                byte param4 = splitOne[2].contains(".") ? Byte.parseByte(splitOne[2].split("\\.")[1]) : (byte) 0;
                int param5 = 0;
                int param6 = 0;
                int param7 = 0;
                int param8 = 0;
                int param9 = splitOne[2].contains(".") ? Integer.parseInt(splitOne[2].split("\\.")[0]) : Integer.parseInt(splitOne[2]);
                int param10 = dbArea;
                String output;
//                if ("Int".equals(split[1])) {
//                    System.out.println("Siemens_" + lineNum + "(\"" + split[2] + "\",\"" + name + split[0] + "\",\"" + "int\",(byte)" + 0 + "," + 54 + "),");
                output = String.format("Siemens_%d(\"%s\", \"%s\", \"%s\", %d, %d, %d, %d, %d, %d, %d),",
                        param0, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);
//                } else if ("Bool".equals(split[1])) {
//                    System.out.println("Siemens_" + lineNum + "(\"" + split[2] + "\",\"" + name + split[0] + "\",\"" + "boolean\",(byte)" + 0 + "," + 54 + "),");
                output = String.format("Siemens_%d(\"%s\", \"%s\", \"%s\", %d, %d, %d, %d, %d, %d, %d),",
                        param0, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);
//                } else if ("Time".equals(split[1])) {
//                    System.out.println("Siemens_" + lineNum + "(\"" + split[2] + "\",\"" + name + split[0] + "\",\"" + "time\",(byte)" + 0 + "," + 54 + "),");
                output = String.format("Siemens_%d(\"%s\", \"%s\", \"%s\", %d, %d, %d, %d, %d, %d, %d),",
                        param0, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);
//                }
                System.out.println(output);
                lineNum++;

                //System.out.println("<el-button @click=" + "\"siemensSignalActivate('" + name + splitOne[0] + "')" + "\">" + name + splitOne[0] + "</el-button>");
            }
            System.out.println(lastLine);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
